import {RouteRecordRaw,createRouter,createWebHistory} from 'vue-router'
import Login from '../views/Login.vue'
import Home from '../views/Home.vue'
const routes:Array<RouteRecordRaw>=[
    {
        path:'/login',
        component:Login
    },
    {
        path:'/',
        component:Home,
        children:[
            {
                path:'/',
                component:()=>import('../views/Main.vue')
            },
            {
                path:'/userList',
                component:()=>import('../views/UserList.vue')
            },
            {
                path:'/categoryList',
                component:()=>import('../views/CategoryList.vue')
            },
            {
                path:'/goodsList',
                component:()=>import('../views/GoodsList.vue')
            }
        ],
        redirect:'/main'
    }
]
const router=createRouter({
    routes,
    history:createWebHistory()
})
router.beforeEach(to=>{
    const token=localStorage.getItem("token")
    if(!token&&to.path!=='/login'){
        return "/login"
    }
})
export default router